package com.ihr360.payroll.calc;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.ihr360.commons.model.meta.table.DynamicCell;
import com.ihr360.payroll.type.SalaryProfileChangeType;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 对于分段的人，一个人的计算结果要考虑分段信息和汇总信息的保存 SalaryProfileItemsWrapper 目前是满足不了修改的，需要
 * 重新设计
 */
public class StaffSalaryCalcPeriodTerm implements Serializable {
    /**
     * 分段开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8" )
    private Date startOn;
    /**
     * 分段结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date endOn;

    /**
     * 分段原因
     */
    private SalaryProfileChangeType changeType;

    private Map<String, DynamicCell> items;

    public StaffSalaryCalcPeriodTerm() {
    }

    public StaffSalaryCalcPeriodTerm(Date startOn, Date endOn) {
        this.startOn = startOn;
        this.endOn = endOn;
    }

    public Date getStartOn() {
        return startOn;
    }

    public void setStartOn(Date startOn) {
        this.startOn = startOn;
    }

    public Date getEndOn() {
        return endOn;
    }

    public void setEndOn(Date endOn) {
        this.endOn = endOn;
    }

    public Map<String, DynamicCell> getItems() {
        return items;
    }

    public void setItems(Map<String, DynamicCell> items) {
        this.items = items;
    }

    public void addItem(String field, String value) {
        if (items == null) {
            this.items = new HashMap<>();
        }
        if (value==null){
            this.items.remove(field);
        }else{
            this.items.put(field, new DynamicCell(value));
        }
    }

    public void addVoidItem(String field) {
        if (items == null) {
            this.items = new HashMap<>();
        }
        this.items.remove(field);
    }

    public void addItem(String field, DynamicCell value) {
        if (items == null) {
            this.items = new HashMap<>();
        }
        if (value!=null){
            this.items.put(field, value);
        }else{
            this.items.remove(field);
        }
    }

    public void clearItems() {
        if (this.items != null) {
            this.items.clear();
        }
        this.items = null;
    }
}